package chart;

import java.io.IOException;
import java.util.Calendar;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;

import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;

import org.xml.sax.SAXException;

import settings.MasterController;

//@author U096819H
public class ReportValues {
	// @author U096819H
	public ReportValues() {

	}

	// @author U096819H
	private String findMax(Map<String, Double> list) {
		Double maxValueInMap = (Collections.max(list.values()));
		for (Entry<String, Double> entry : list.entrySet()) {
			if (entry.getValue() == maxValueInMap) {
				return entry.getKey();
			}
		}
		return "";
	}

	// @author U096819H
	private String findMin(Map<String, Double> list) {
		Double minValueInMap = (Collections.min(list.values()));
		for (Entry<String, Double> entry : list.entrySet()) {
			if (entry.getValue() == minValueInMap) {
				return entry.getKey();
			}
		}
		return "";
	}

	// @author U096819H
	public String getMaxCatExp(MasterController mc)
			throws TransformerConfigurationException, InstantiationException,
			IllegalAccessException, JAXBException,
			ParserConfigurationException, SAXException, IOException,
			TransformerException {
		Map<String, Double> expList = new TreeMap();
		expList = mc.GetTotalExpenseByCategory();
		return findMax(expList);
	}

	// @author U096819H
	public String getMinCatExp(MasterController mc)
			throws TransformerConfigurationException, InstantiationException,
			IllegalAccessException, JAXBException,
			ParserConfigurationException, SAXException, IOException,
			TransformerException {
		Map<String, Double> expList = new TreeMap();
		expList = mc.GetTotalExpenseByCategory();
		return findMin(expList);
	}

	// @author U096819H
	public String getMaxCatInc(MasterController mc)
			throws TransformerConfigurationException, InstantiationException,
			IllegalAccessException, JAXBException,
			ParserConfigurationException, SAXException, IOException,
			TransformerException {
		Map<String, Double> incList = new TreeMap();
		incList = mc.GetTotalIncomeByCategory();
		return findMax(incList);
	}

	// @author U096819H
	public String getMinCatInc(MasterController mc)
			throws TransformerConfigurationException, InstantiationException,
			IllegalAccessException, JAXBException,
			ParserConfigurationException, SAXException, IOException,
			TransformerException {
		Map<String, Double> incList = new TreeMap();
		incList = mc.GetTotalIncomeByCategory();
		return findMin(incList);
	}

	// @author U096819H
	public String getMaxSrcExp(MasterController mc)
			throws TransformerConfigurationException, InstantiationException,
			IllegalAccessException, JAXBException,
			ParserConfigurationException, SAXException, IOException,
			TransformerException {
		Map<String, Double> expList = new TreeMap();
		expList = mc.GetTotalExpenseBySource();
		return findMax(expList);
	}

	// @author U096819H
	public String getMinSrcExp(MasterController mc)
			throws TransformerConfigurationException, InstantiationException,
			IllegalAccessException, JAXBException,
			ParserConfigurationException, SAXException, IOException,
			TransformerException {
		Map<String, Double> expList = new TreeMap();
		expList = mc.GetTotalExpenseBySource();
		return findMin(expList);
	}

	// @author U096819H
	public String getMaxSrcInc(MasterController mc)
			throws TransformerConfigurationException, InstantiationException,
			IllegalAccessException, JAXBException,
			ParserConfigurationException, SAXException, IOException,
			TransformerException {
		Map<String, Double> incList = new TreeMap();
		incList = mc.GetTotalIncomeBySource();
		return findMax(incList);
	}

	// @author U096819H
	public String getMinSrcInc(MasterController mc)
			throws TransformerConfigurationException, InstantiationException,
			IllegalAccessException, JAXBException,
			ParserConfigurationException, SAXException, IOException,
			TransformerException {
		Map<String, Double> incList = new TreeMap();
		incList = mc.GetTotalIncomeBySource();
		return findMin(incList);
	}
}
